from typing import Generic, TypeVar, Optional
from pydantic import BaseModel, Field

T = TypeVar('T')  # 泛型类型，用于data字段

class BaseResponse(BaseModel, Generic[T]):
    code: int = Field(200, description="状态码")
    message: str = Field("success", description="提示信息")
    data: Optional[T] = Field(None, description="返回数据")

    class Config:
        json_schema_extra = {
            "example": {
                "code": 200,
                "message": "操作成功",
                "data": None
            }
        }